package lib


func init() {
	Probs = append(Probs, Problem{
		Num:         454,
		Discription: "从四个数组里各取一个数和为0的下标组合个数",
		Level:       2,
		Labels: map[string]int{
			"哈希表": 1,
		},
	})
}

//因为下标不一样就行，所以不需要排序去重
//两两数组组合，计算各取一个相加能得到的每种和的数量
//然后再val 和 -val匹配，两者数量相乘
func FourSumCount(nums1 []int, nums2 []int, nums3 []int, nums4 []int) int {
	valMap1 := make(map[int]int, 0)
	for _, val1 := range nums1 {
		for _, val2 := range nums2 {
			valMap1[val1+val2]++
		}
	}

	valMap2 := make(map[int]int, 0)
	for _, val1 := range nums3 {
		for _, val2 := range nums4 {
			valMap2[val1+val2]++
		}
	}

	res := 0
	for val, count1 := range valMap1 {
		count2, exist := valMap2[-val]
		if exist {
			res += count1 * count2
		}
	}

	return res
}
